package org.kumas.sgrpc.rpc.protocol.sgrpc;

import org.kumas.sgrpc.common.URL;
import org.kumas.sgrpc.common.utils.StringUtils;
import org.kumas.sgrpc.remoting.RemotingServer;
import org.kumas.sgrpc.rpc.ProtocolServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author KumasZhang
 * @version 1.0
 * @since 2021-07-27 13:43
 */
public class SgrpcProtocolServer implements ProtocolServer {

    private static final Logger LOGGER = LoggerFactory.getLogger(SgrpcProtocolServer.class);

    private RemotingServer server;
    private String address;

    public SgrpcProtocolServer(RemotingServer server) {
        this.server = server;
    }

    @Override
    public RemotingServer getRemotingServer() {
        return server;
    }

    @Override
    public String getAddress() {
        return StringUtils.isNotEmpty(address) ? address : server.getUrl().getAddress();
    }

    @Override
    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public URL getUrl() {
        return server.getUrl();
    }

    @Override
    public void reset(URL url) {
        LOGGER.info("[neet to do] not implement");
    }

    @Override
    public void close() {
        server.close();
    }
}
